///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// It is common ui which support move window if parent ui is frameless 
///</describe>
/// <date>2020/7/26</date>
///***********************************************************************
#ifndef COMMONHEADER_H
#define COMMONHEADER_H

#include <QFrame>
#include <QMouseEvent>
#include <QPoint>

class CommonHeader :public QFrame
{
	Q_OBJECT

public:
    // Construct the test ui
	explicit CommonHeader(QWidget* parent = NULL);

    // Destruct the test ui
    virtual ~CommonHeader();

protected:
	// Override event handler function to support resize frameless window
	virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);

	// Show the frame
	virtual void showEvent(QShowEvent *ev);

	// Press the window
	virtual void mousePressEvent(QMouseEvent *e);

	// Move the window
	virtual void mouseMoveEvent(QMouseEvent *e);

	// Release the mouse
	void mouseReleaseEvent(QMouseEvent *ev);
	
private:
	// Init the UI
	void Initialize();

	// Destory the UI
	void Destory();

private:
	//Get the IsCanMove
	bool GetIsCanMove() const
	{
		return m_bIsCanMove;
	}

	//Set the IsCanMove
	void SetIsCanMove(bool bIsCanMove)
	{
		m_bIsCanMove = bIsCanMove;
	}

	//Get the Disposed
	bool GetDisposed() const
	{
		return m_bDisposed;
	}

	//Set the Disposed
	void SetDisposed(bool bDisposed)
	{
		m_bDisposed = bDisposed;
	}

private:
	// Record the mouse point
	QPoint m_LastClickPos;

	// Is can move
	bool m_bIsCanMove;

	// Disposed status
	bool m_bDisposed;
};

#endif // COMMONHEADER_H
